Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
How does -5 >> 2 === -2?

In the MDN docs, there is this example below under right shift operator.

const a = 5;          //  00000000000000000000000000000101
const b = 2;          //  00000000000000000000000000000010
const c = -5;         // -00000000000000000000000000000101

console.log(a >> b);  //  00000000000000000000000000000001
// expected output: 1

console.log(c >> b);  // -00000000000000000000000000000010
// expected output: -2

5 >> 2 makes sense because you shift the digits right 2 spaces. In the second example of -5 >> 2, why does it only seemingly shift to the right one space even though it's >> 2?

MDN Docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Right_shift

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Just like Johnny side, you might want to check the Two's complement rule. The number in left most might be 1 inside of 0. You might want to check the example with -9 this example will help you understand better.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!